package com.wwtech.epp.ui.adapter.work;

import android.content.Context;
import android.os.Environment;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.socks.library.KLog;
import com.wwtech.epp.R;
import com.wwtech.epp.entity.AttachmentBean;
import com.wwtech.epp.entity.TaskAttachmentFile;
import com.wwtech.epp.entity.TaskDetail;

import java.io.File;
import java.util.List;

/**
 * Created by huzhipeng on 2017/12/8.
 */

public class LookAttachmentAdapter extends BaseQuickAdapter<TaskAttachmentFile, BaseViewHolder> {

    private String sPath;

    public LookAttachmentAdapter(@Nullable List<TaskAttachmentFile> data) {
        super(R.layout.item_look_attachment, data);
    }

    public void initFilePath(Context context) {
        sPath = Environment.getExternalStorageDirectory() + "/" + context.getPackageName() + "/taskFile";
        KLog.i("全路径为：" + sPath);
        File path = new File(sPath);
        if (!path.exists()) {
            path.mkdirs();
        }
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, TaskAttachmentFile bean) {
        baseViewHolder.addOnClickListener(R.id.iv_opreate);
        baseViewHolder.setText(R.id.name, bean.getFileName());
        baseViewHolder.addOnClickListener(R.id.iv_opreate);
        baseViewHolder.addOnClickListener(R.id.tv_preview);
        File f = new File(sPath + "/" + bean.getFileName());
        if (f.exists()) {
            baseViewHolder.setText(R.id.iv_opreate, "查看");
        } else {
            baseViewHolder.setText(R.id.iv_opreate, "下载");
        }
    }
}
